Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents txtBase As System.Windows.Forms.TextBox Friend WithEvents TxtTarget As System.Windows.Forms.TextBox Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents TxtExponent As System.Windows.Forms.TextBox Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents BtnCalc As System.Windows.Forms.Button Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label Me.Label2 = New System.Windows.Forms.Label Me.txtBase = New System.Windows.Forms.TextBox Me.TxtTarget = New System.Windows.Forms.TextBox Me.Label3 = New System.Windows.Forms.Label Me.TxtExponent = New System.Windows.Forms.TextBox Me.Label4 = New System.Windows.Forms.Label Me.BtnCalc = New System.Windows.Forms.Button Me.SuspendLayout() ' 'Label1 ' Me.Label1.AutoSize = True Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 24.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(152, 32) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(156, 49) Me.Label1.TabIndex = 0 Me.Label1.Text = "Powers" ' 'Label2 ' Me.Label2.Location = New System.Drawing.Point(32, 120) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(64, 32) Me.Label2.TabIndex = 1 Me.Label2.Text = "Base" ' 'txtBase ' Me.txtBase.Location = New System.Drawing.Point(120, 120) Me.txtBase.Name = "txtBase" Me.txtBase.Size = New System.Drawing.Size(72, 22) Me.txtBase.TabIndex = 2 Me.txtBase.Text = "2" ' 'TxtTarget ' Me.TxtTarget.Location = New System.Drawing.Point(120, 160) Me.TxtTarget.Name = "TxtTarget" Me.TxtTarget.Size = New System.Drawing.Size(72, 22) Me.TxtTarget.TabIndex = 4 Me.TxtTarget.Text = "" ' 'Label3 ' Me.Label3.Location = New System.Drawing.Point(32, 160) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(64, 32) Me.Label3.TabIndex = 3 Me.Label3.Text = "Target" ' 'TxtExponent ' Me.TxtExponent.Location = New System.Drawing.Point(120, 248) Me.TxtExponent.Name = "TxtExponent" Me.TxtExponent.ReadOnly = True Me.TxtExponent.Size = New System.Drawing.Size(72, 22) Me.TxtExponent.TabIndex = 6 Me.TxtExponent.Text = "" ' 'Label4 ' Me.Label4.Location = New System.Drawing.Point(32, 248) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(64, 32) Me.Label4.TabIndex = 5 Me.Label4.Text = "Exponent" ' 'BtnCalc ' Me.BtnCalc.Location = New System.Drawing.Point(104, 200) Me.BtnCalc.Name = "BtnCalc" Me.BtnCalc.Size = New System.Drawing.Size(88, 32) Me.BtnCalc.TabIndex = 7 Me.BtnCalc.Text = "Calculate" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15) Me.ClientSize = New System.Drawing.Size(480, 448) Me.Controls.Add(Me.BtnCalc) Me.Controls.Add(Me.TxtExponent) Me.Controls.Add(Me.Label4) Me.Controls.Add(Me.TxtTarget) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.txtBase) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Private Sub BtnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCalc.Click If IsNumeric(txtBase.Text) And IsNumeric(TxtTarget.Text) Then Dim base As Double base = Convert.ToDouble(txtBase.Text) Dim target As Double target = Convert.ToDouble(TxtTarget.Text) 'If base > 1 And target >= 1 Then Dim exponent As Integer = 0 Dim calc As Double = base ^ exponent Do While calc < target ' haven't reached target yet - up exponent exponent = exponent + 1 calc = base ^ exponent Loop ' if we get out here we have reached target TxtExponent.Text = exponent.ToString("") 'Else 'MsgBox("this won't work well with base or target below 1") 'End If Else MsgBox("Please ensure that values entered are numeric") End If End Sub End Class